﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Liquid.Collections {
	public sealed class WeakList<T> : WeakCollection<T>, IList<T>
		where T : class {
		public int IndexOf(T item) {
			Compact();
			return Inner.IndexOf(i => IsEqual(i, item));
		}

		public void Insert(int index, T item) {
			var copy = Compact();
			Inner.Insert(index, new WeakReference(item));
		}

		public void RemoveAt(int index) {
			var copy = Compact();
			Inner.RemoveAt(index);
		}

		public T this[int index] {
			get {
				var copy = Compact();
				return copy[index];
			}
			set {
				var copy = Compact();
				Inner[index] = new WeakReference(value);
			}
		}
	}
}
